package design.single;

import java.util.concurrent.CountDownLatch;

/**
 * Created by admin on 2019/3/12.
 * 多线程下的效率测试
 */
public class ThreadsTest {
    public static void main(String[] args) throws Exception {
        int threadnum = 10;
        final  CountDownLatch countDownLatch = new CountDownLatch(threadnum);//类似多线程计数器
        long startTime = System.currentTimeMillis();
        for (int i = 0; i < threadnum; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int i = 0; i < 100000; i++) {
                        Singleton2 s =   Singleton2.getSingleton2();
                    }
                    countDownLatch.countDown();
                }
            }).start();
        }
        countDownLatch.await();//等待线程计数器为零 才执行一下的代码
        long endTime = System.currentTimeMillis();
        System.out.println("共用时间"+(endTime-startTime));

    }
}
